package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.api.dto.ImparityGoodsDto;
import com.sale.goods.api.vo.GetDataByCodeGoodsVo;
import com.sale.goods.domain.dto.GoodsIncomeDto;
import com.sale.goods.domain.dto.ReceiptAndPaymentDocDto;
import com.sale.goods.domain.vo.GoodsIncomeVo;
import com.sale.goods.service.IGoodsIncomeService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 其他收入单
 * @Date 23-08-07
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/income")
public class GoodsIncomeController extends BaseController {

    private final IGoodsIncomeService goodsIncomeService;

    /**
     * 获取其他收入单
     */
    //@SaCheckPermission("finance:income:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsIncomeDto> list(GoodsIncomeVo goodsIncomeVo, PageQuery pageQuery)
    {
        return goodsIncomeService.selectIncomeList(goodsIncomeVo,pageQuery);
    }

    /**
     * 获取其他收入单 (弹框)
     */
    @GetMapping("/listPop")
    public TableDataInfo<ReceiptAndPaymentDocDto> listPop(GoodsIncomeVo goodsIncomeVo, PageQuery pageQuery)
    {
        return goodsIncomeService.selectIncomePopList(goodsIncomeVo,pageQuery);
    }


    /**
     * 新增其他收入单
     */
    //@SaCheckPermission("finance:income:add")
    @Log(title = "其他收入单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsIncomeVo goodsIncomeVo) throws Exception {
        return toAjax(goodsIncomeService.insertIncome(goodsIncomeVo));
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/{incomeId}")
    //@SaCheckPermission("finance:income:query")
    public R getInfo(@PathVariable long incomeId)
    {
        return R.ok(goodsIncomeService.selectIncomeById(incomeId));
    }

    /**
     * 删除收款单
     */
    //@SaCheckPermission("finance:income:remove")
    @Log(title = "其他收入单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{incomeId}")
    public R<Void> remove(@PathVariable("incomeId") Long incomeId) {
        return toAjax(goodsIncomeService.deleteIncomeById(incomeId));
    }

    /**
     * 修改收款单
     */
    //@SaCheckPermission("finance:income:edit")
    @Log(title = "其他收入单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsIncomeVo goodsIncomeVo) {
        return toAjax(goodsIncomeService.updateIncomeEdit(goodsIncomeVo));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:income:subExamine")
    @Log(title = "其他收入单", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{incomeId}")
    public R<Void> submitReview(@PathVariable("incomeId") Long incomeId) {
        return toAjax(goodsIncomeService.submitReview(incomeId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:income:revoke")
    @Log(title = "其他收入单", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{incomeId}")
    public R<Void> deleteReview(@PathVariable("incomeId") Long incomeId) {
        return toAjax(goodsIncomeService.deleteReview(incomeId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("finance:income:examine")
    @Log(title = "其他收入单", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsIncomeVo goodsIncomeVo) throws Exception {
        return toAjax(goodsIncomeService.goodSExamineReview(goodsIncomeVo));
    }

    /**
     * 财务-核销单 通过获取未全部核销的其他收入单数据
     */
    @GetMapping("/getNoVerificationList")
    public List<ImparityGoodsDto> getNoVerificationList(GetDataByCodeGoodsVo getDataByCodeVo) {
        return goodsIncomeService.getNoVerificationList(getDataByCodeVo);
    }
}
